<template>
  <div class="login-panel">
    <el-tabs type="border-card" class="demo-tabs" stretch v-model="currentTab">
      <el-tab-pane name="account">
        <template #label>
          <span class="custom-tabs-label">
            <el-icon class="avatar"><Avatar /></el-icon>
            <span>账号登录</span>
          </span>
        </template>
        <login-account ref="accountLoginRef" />
      </el-tab-pane>
      <el-tab-pane name="phone">
        <template #label>
          <span class="custom-tabs-label">
            <el-icon><Iphone /></el-icon>
            <span>手机登录</span>
          </span>
        </template>
        <login-phone ref="phoneLoginRef" />
      </el-tab-pane>
    </el-tabs>

    <div class="account-control">
      <el-checkbox v-model="isKeepPasswrod">记住密码</el-checkbox>
      <el-link type="primary">忘记密码</el-link>
    </div>

    <el-button class="login-btn" @click="handleLoginClick">立即登录</el-button>
  </div>
</template>

<script lang="ts">
import { defineComponent, ref } from 'vue'
import { Avatar, Iphone } from '@element-plus/icons-vue'
import loginAccount from './login-account.vue'
import loginPhone from './login-phone.vue'

export default defineComponent({
  components: {
    loginAccount,
    loginPhone,
    Avatar,
    Iphone
  },
  setup() {
    const isKeepPasswrod = ref(true)
    const currentTab = ref('account')
    const accountLoginRef = ref<InstanceType<typeof loginAccount>>()
    const phoneLoginRef = ref<InstanceType<typeof loginPhone>>()

    const handleLoginClick = () => {
      if (currentTab.value == 'account') {
        accountLoginRef.value?.accountLogin(isKeepPasswrod.value)
      } else {
        console.log(phoneLoginRef)
      }
    }

    return {
      isKeepPasswrod,
      currentTab,
      accountLoginRef,
      phoneLoginRef,
      handleLoginClick
    }
  }
})
</script>

<style lang="less" scoped>
.login-panel {
  margin: 0 auto;
  padding: 0 30px;
  .el-tabs__item {
    text-align: center;
  }
  .account-control {
    display: flex;
    justify-content: space-between;
    margin-top: 8px;
  }

  .login-btn {
    padding: 24px 0;
    margin-top: 13px;
    user-select: none;
    text-align: center;
    font-size: 15px;
    border: none;
    width: 100%;
    background: linear-gradient(to right, #a6c1ee, #fbc2eb);
    color: #fff;
  }
}
</style>
